#ifndef _CLIENTENGINE_
#define	_CLIENTENGINE_

#include <iostream>
#include <string>
#include "Graphics/Camera.hpp"
#include "Engine.hpp"
#include "NetworkHandler.hpp"
#include "UI/ChatBox.hpp"
#include "Content/Map.hpp"
#include "Content/MapLoader.hpp"
#include "Objects/ClientEntityManager.hpp"
#include "Objects/ClientRegionManager.hpp"
#include "Utilities/IntervalCounter.hpp"
#include "Utilities/Logger.hpp"

using namespace std;

class ClientEngine:public Engine, public sf::Drawable{
private:
    
    /**
    * Timer to keep track of engine time.
    */
    sf::Clock gameTimer;
    
    /**
    * Time at the beginning of current frame.
    */
    unsigned int frameTime;
    
    unsigned int keepAliveTime;

public:
	//Debug displays

	/** 
	* Frame per second counter
	*/
	IntervalCounter fpsCounter;
	Label fpsLabel;

	/** 
	* Messages in per second counter
	*/
	IntervalCounter mipsCounter;
	Label mipsLabel;

	/** 
	* Messages out per second counter
	*/
	IntervalCounter mopsCounter;
	Label mopsLabel;

    bool hasFocus;
    
    byte playerIndex;
    byte playerCount;
    
    NetworkHandler* networkHandler;
    Map* map;
    Camera* camera;

	ClientEntityManager entityManager;
    ClientRegionManager regionManager;
    
    //UI
    UIManager ui;
    ChatBox chatBox;
    sf::RenderWindow* window;

    bool run;

    ClientEngine(sf::RenderWindow* renderWindow, NetworkHandler* network, std::string mapName,
        Camera* gameCamera, byte clientIndex, Packet_GameState* gameState);
    
    virtual void update();
    virtual void handleEvents();
    virtual void handleInput();
    virtual void handleMessages(MessageQueue* messages, unsigned int serverTime);

    void disconnect();

    virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;

    virtual ~ClientEngine();
};


#endif

